<template>
  <div class="excelExport">
    <div class="excelExport_btns">
      <el-popover
        placement="bottom"
        width="180"
        popper-class="downLoad-excel-popper"
        trigger="click"
      >
        <div class="excelExport_downLoadList">
          <div>
            <el-checkbox v-model="allSelect" @change="AllDelChange">全选</el-checkbox>
          </div>
          <div v-for="(item,index) in myDownLoadList" :key="index">
            <el-checkbox v-model="item.isSelect">{{item.label}}</el-checkbox>
          </div>
          <div class="tc mt10">
            <el-popover
              placement="bottom"
              width="80"
              popper-class="downLoad-excel-btn-popper"
              trigger="click"
            >
              <el-button
                size="mini"
                type="success"
                class="mb10 db"
                :loading="downloadLoading"
                @click="exportExcel(true)"
              >所有数据</el-button>
              <el-button
                size="mini"
                type="warning"
                class="db"
                :loading="downloadLoading"
                @click="exportExcel(false)"
              >查询结果</el-button>
              <div slot="reference">
                <el-button type="primary" size="mini" @click="isBtnShow = !isBtnShow">导出</el-button>
                <el-tooltip
                  content="未勾选的表格列将不会导出，导出所有数据会导出您该表格的所有数据，而导出查询结果会根据您选择的列表查找结果导出。"
                  placement="bottom"
                  popper-class="downLoad-excel-tips-popper"
                  effect="light"
                >
                  <i class="el-icon-question"></i>
                </el-tooltip>
              </div>
            </el-popover>
          </div>
        </div>
        <el-button slot="reference" class="mr20 exportExcel" icon="el-icon-download" @click="isShow = !isShow">导出列表</el-button>
      </el-popover>
    </div>

    <div id="exportExcelTemplate" hidden style="display: none"></div>
  </div>
</template>

<script>
import xyFileSaver from "file-saver";
import Vue from "vue/dist/vue.esm.js";
import xyXLSX from "xlsx";
import moment from "moment";

export default {
  data() {
    return {
      myDownLoadList: this.downLoadList,
      downloadLoading: false,
      allSelect: true,
      // 点击导出列表
      isShow: false,
      // 点击导出按钮
      isBtnShow: false
    };
  },
  props: {
    downLoadList: {
      type: Array,
      default: function () {
        return [];
      },
    },
    excelName: {
      type: String,
      default: "导出列表",
    },
  },
  methods: {
    AllDelChange(val) {
      for (let i = 0; i < this.myDownLoadList.length; i++) {
        this.$set(this.myDownLoadList[i], "isSelect", val);
      }
      this.$emit("update:downLoadList", this.myDownLoadList);
    },
    exportExcel(all) {
      this.isShow = false
      this.isBtnShow = false
      this.$emit("exportExcel", this.excelName, all);
    },

    // 异常数据表导出
    exportExcelAbonormal(tabName, tabHandle, tableData) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            tabRowStr += `<td>${
              data[handle.props] ? data[handle.props] : ""
            }</td>`;
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 代理人列表导出
    exportExcelAgent(tabName, tabHandle, tableData) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            if (handle.props == "channelName") {
              tabRowStr += `<td>${
                data.channel_agent ? data.channel_agent.name : ""
              }</td>`;
            } else if (handle.props == "is_teacher") {
              tabRowStr += `<td>${data.is_teacher == 1 ? "导师" : "徒弟"}</td>`;
            } else if (handle.props == "relation") {
              tabRowStr += `<td>${this.getTeacher(data)}</td>`;
            } else if (handle.props == "workingTime") {
              tabRowStr += `<td>${this.oneThejobDay(data.created_at)}</td>`;
            } else if (handle.props == "created_at") {
              tabRowStr += `<td>${this.formatTime(data.created_at)}</td>`;
            } else if (handle.props == "relation") {
              tabRowStr += `<td>${this.getTeacher(data)}</td>`;
            } else if (handle.props == "vip") {
              tabRowStr += `<td>${data.vip == 1 ? "是" : "否"}</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 提现审核
    exportExcelWithdraw(tabName, tabHandle, tableData,count) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      let sumTr = ''
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";
      let moneyIndex = 0
      tableData.forEach((data, index) => {
        let tabRowStr = "";
        let noSelectCount = 0
        tabStr += `<tr><td>${index + 1}</td>`;

        
        tabHandle.forEach((handle,hIndex) => {
          if (handle.isSelect) {
            if (handle.props == "name") {
              tabRowStr += `<td>${data.user ? data.user.name : ""}</td>`;
            } else if (handle.props == "user_type") {
              tabRowStr += `<td>${
                data.user_type == 1 ? "代理人" : "用户"
              }</td>`;
            } else if (handle.props == "phone") {
              tabRowStr += `<td>${data.user ? data.user.phone : ""}</td>`;
            } else if (handle.props == "to_type") {
              tabRowStr += `<td>${
                data.withdrawal_records
                  ? data.withdrawal_records.type == 1
                    ? "支付宝"
                    : "银行卡"
                  : ""
              }</td>`;
            } else if (handle.props == "status") {
              tabRowStr += `<td>${this.withdrawStatus(data.status)}</td>`;
            } else if (handle.props == "number") {
              tabRowStr += `<td>${
                data.withdrawal_records ? data.withdrawal_records.num : ""
              }</td>`;
            } else if (handle.props == "user_name") {
              tabRowStr += `<td>${
                data.withdrawal_records ? data.withdrawal_records.payee : ""
              }</td>`;
            } else if (handle.props == "bank") {
              tabRowStr += `<td>${
                data.withdrawal_records
                  ? data.withdrawal_records.sub_branch
                    ? data.withdrawal_records.sub_branch
                    : ""
                  : ""
              }</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;

            }
          } else {
            noSelectCount ++ 
          }
        
          if (handle.props == 'money' && handle.isSelect) {
            moneyIndex = hIndex - noSelectCount 
          }
        });



        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      if (moneyIndex) {
        sumTr = '<tr><td>合计</td>'
        for (let i = 0; i < moneyIndex; i++) {
          sumTr += `<td></td>`
        }
        sumTr += `<td>${count.total_money}</td></tr>`
        str += sumTr
      }
      
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 国知局前订单导出
    exportExcelOrder(tabName, tabHandle, tableData) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].noExport) {
          continue;
        } else {
          if (tabHandle[tabHandleKey].isSelect) {
            str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
          }
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.noExport) {
            return;
          } else {
            if (handle.isSelect) {
              if (
                handle.props == "waitingTime" ||
                handle.props == "getSumTime"
              ) {
                tabRowStr += `<td>${this.getOrderTime(data.created_at)}</td>`;
              } else if (handle.props == "getProcessingTime") {
                if (data.pick_up_date) {
                  tabRowStr += `<td>${this.getProcessingTime(
                    data.pick_up_date
                  )}</td>`;
                } else {
                  tabRowStr += `<td>${this.getProcessingTime(
                    data.created_at
                  )}</td>`;
                }
              } else if (handle.props == "process") {
                tabRowStr += `<td>${
                  data.process ? data.process.name : ""
                }</td>`;
              } else if (handle.props == "agent") {
                tabRowStr += `<td>${this.agentNumAddName(data.agent)}</td>`;
                // 提交时间
              } else if (handle.props == "submitTime") {
                tabRowStr += `<td>${this.findData(data)}</td>`;
              } else if (handle.props == "referral_code") {
                tabRowStr += `<td>${this.channelPid(data.consumer)}</td>`;
              } else if (handle.props == "is_frozen") {
                tabRowStr += `<td>${data.is_frozen == 1 ? '冻结中' : data.is_frozen == 2 ? "未冻结" : '已申请'}</td>`;
              } else if (handle.props == "frozen_opinions") {
                tabRowStr += `<td>${data.frozen_opinions && data.frozen_opinions.length ? JSON.parse(data.frozen_opinions[0].review).reason : '' }</td>`;
              } else {
                tabRowStr += `<td>${
                  data[handle.props] ? data[handle.props] : ""
                }</td>`;
              }
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 国知局后订单导出
    exportExcelFinals(tabName, tabHandle, tableData) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            if (handle.props == "waitSubmitTime") {
              tabRowStr += `<td>${this.getWaitSubmitTime(data)}</td>`;
            } else if (handle.props == "type") {
              tabRowStr += `<td>${
                data.type == "F"
                  ? "发明专利"
                  : data.type == "S"
                  ? "实用新型"
                  : "外观设计"
              }</td>`;
            } else if (handle.props == "patent_user") {
              tabRowStr += `<td>${
                data.order ? data.order.patent_user : ""
              }</td>`;
            } else if (handle.props == "user_name") {
              tabRowStr += `<td>${data.order ? data.order.user_name : ""}</td>`;
            } else if (handle.props == "liaisons") {
              tabRowStr += `<td>${data.order ? data.order.liaisons : ""}</td>`;
            } else if (handle.props == "id_card") {
              tabRowStr += `<td>${data.order ? data.order.id_card : ""}</td>`;
            } else if (handle.props == "liaisons_email") {
              tabRowStr += `<td>${
                data.order ? data.order.liaisons_email : ""
              }</td>`;
            } else if (handle.props == "remarks") {
              tabRowStr += `<td>${data.order ? data.order.remarks : ""}</td>`;
            } else if (handle.props == "same_day_number") {
              tabRowStr += `<td>${
                data.order
                  ? data.order.same_day_number
                    ? data.order.same_day_number
                    : "无同日提交案件"
                  : ""
              }</td>`;
            } else if (handle.props == "consumer_pay_status") {
              tabRowStr += `<td>${this.payStatus(
                data.consumer_pay_status
              )}</td>`;
            } else if (handle.props == "priority_reviewl") {
              tabRowStr += `<td>${
                data.final_status
                  ? data.final_status.priority_reviewl == 1
                    ? "可优先审查"
                    : ""
                  : ""
              }</td>`;
            } else if (handle.props == "agent") {
              tabRowStr += `<td>${this.agentNumAddName(data.agent)}</td>`;
            } else if (handle.props == "process") {
              tabRowStr += `<td>${
                data.order
                  ? data.order.process
                    ? data.order.process.name
                    : ""
                  : ""
              }</td>`;
            } else if (handle.props == "orderTakingTime") {
              tabRowStr += `<td>${this.getOrderTakingTime(data)}</td>`;
            } else if (handle.props == "usetSubmitTime") {
              tabRowStr += `<td>${
                data.order ? data.order.created_at : "导入数据"
              }</td>`;
            } else if (handle.props == "referral_code") {
              tabRowStr += `<td>${
                data.order ? this.channelPid(data.order.consumer) : ""
              }</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 结算统计导出
    exportFinialSum(tabName, tabHandle, tableData, type) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            if (handle.props == "waitSubmitTime") {
              tabRowStr += `<td>${this.getWaitSubmitTime(data)}</td>`;
            } else if (handle.props == "deduction_explain") {
              tabRowStr += `<td>${this.getExplainData(
                data.deduction_explain
              )}</td>`;
            } else if (handle.props == "reward_explain") {
              tabRowStr += `<td>${this.getExplainData(
                data.reward_explain
              )}</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 我的收益导出
    exportExcelEarnings(tabName, tabHandle, tableData, type) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            if (handle.props == "type") {
              tabRowStr += `<td>${
                data.final ? this.typeFilter(data.final.type) : data.type
              }</td>`;
            } else if (handle.props == "finalName") {
              tabRowStr += `<td>${data.final ? data.final.name : data.name}</td>`;
            } else if (handle.props == "liaisons") {
              tabRowStr += `<td>${
                data.final
                  ? data.final.order
                    ? data.final.order.liaisons
                    : ""
                  : ""
              }</td>`;
            } else if (handle.props == "grades") {
              tabRowStr += `<td>${
                data.final && data.final.grades
                  ? this.getAverage(data.final.grades)
                  : ""
              }</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    exportOnlinePay(tabName, tabHandle, tableData, type) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            if (handle.props == "phone") {
              tabRowStr += `<td>${
                data.consumer ? data.consumer.phone : ""
              }</td>`;
            } else if (handle.props == "pay_type") {
              tabRowStr += `<td>${this.payType(data.pay_type)}</td>`;
            } else if (handle.props == "liaisons") {
              tabRowStr += `<td>${
                data.consumer ? data.consumer.name : ""
              }</td>`;
            } else if (handle.props == "application_number") {
              tabRowStr += `<td>${
                data.final && data.final.application_number ? data.final.application_number : ""
              }</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
        exportExcelUserAllOrder(tabName, tabHandle, tableData) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            tabRowStr += `<td>${
              data[handle.props] ? data[handle.props] : ""
            }</td>`;
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 上月结算导出
    exportExcelLastMonthSettlement(tabName, tabHandle, tableData, type) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            if (handle.props == "order_number") {
              tabRowStr += `<td>${
                data.final ? data.final.order_number : ""
              }</td>`;
            } else if (handle.props == "finalName") {
              tabRowStr += `<td>${data.final ? data.final.name : ""}</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 答复列表导出
    exportExcelAnswer(tabName, tabHandle, tableData, type) {
      let str0 = "<tr><td>序号</td>"; //表头
      let str = ""; //表身
      for (let tabHandleKey in tabHandle) {
        if (tabHandle[tabHandleKey].isSelect) {
          str0 += "<td>" + tabHandle[tabHandleKey].label + "</td>";
        }
      }
      str0 += "</tr>";
      let tabStr = "";

      tableData.forEach((data, index) => {
        let tabRowStr = "";
        tabStr += `<tr><td>${index + 1}</td>`;

        tabHandle.forEach((handle) => {
          if (handle.isSelect) {
            if (handle.props == "reply_time") {
              tabRowStr += `<td>${this.getTimeConsuming(data)}</td>`;
            } else if (handle.props == "type") {
              tabRowStr += `<td>${
                data.type == "F"
                  ? "发明专利"
                  : data.type == "S"
                  ? "实用新型"
                  : "外观设计"
              }</td>`;
            } else if (handle.props == "agent") {
              tabRowStr += `<td>${data.agent ? data.agent.name : ""}</td>`;
            } else if (handle.props == "process") {
              tabRowStr += `<td>${
                data.order && data.order.process ? data.order.process.name : ""
              }</td>`;
            } else if (handle.props == "status_submited_at") {
              tabRowStr += `<td>${this.getPost(data)}</td>`;
            }  else if (handle.props == "status_updated_at") {
              tabRowStr += `<td>${this.getAnswerUpdateTime(data)}</td>`;
            } else {
              tabRowStr += `<td>${
                data[handle.props] ? data[handle.props] : ""
              }</td>`;
            }
          }
        });
        tabStr += tabRowStr;
        tabStr += "</tr>";
      });
      str = tabStr;
      str += "</tr>";
      let data = {
        tabHandle: tabHandle,
        tabData: tableData,
        dataStr: str0 + str,
      };
      let template = new Vue({
        el: "#exportExcelTemplate",
        data: data,
        template: `
          <div id="exportExcelTemplate" style="display: none">
            <table v-html="dataStr">
                  {{dataStr}}
            </table>
          </div>`,
      });
      let wb = xyXLSX.utils.table_to_book(template.$el, {
        raw: true,
      });
      let wbout = xyXLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        xyFileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream",
          }),
          tabName + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    // 处理师徒关系
    getTeacher(data) {
      if (data.is_teacher == 1 && data.student.length != 0) {
        let studentName = data.student.map((v) => v.name).join("、");
        return `徒弟：${studentName}`;
      } else if (data.is_teacher == 2 && data.teacher) {
        return `导师：${data.teacher.name}`;
      } else {
        return "";
      }
    },
    //
    oneThejobDay(value) {
      //获取入职时间戳
      value = value.replace(/-/g, "/");
      var createTime = new Date(value);
      //获取当前的时间戳
      var nowTime = new Date();
      let processingTime = "";
      //获取处理时间戳
      let cha = nowTime - createTime;
      let day = 1000 * 60 * 60 * 24;
      var month = day * 30;
      let year = month * 12;

      // processingTime += (cha / month).toFixed(1)
      let round2 = (cha / month).toFixed(2);
      processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1);
      if (processingTime <= 0) {
        return "0.0";
      } else {
        return processingTime;
      }
    },
    // 处理时间格式
    formatTime(value) {
      return moment(value).format("YYYY-MM-DD");
    },
    //接单等待时长
    getOrderTime(value) {
      //获取接单的时间戳
      let createTime = new Date(value).getTime();
      //获取当前的时间戳
      var nowTime = new Date().getTime();
      //获取处理时间戳
      let cha = nowTime - createTime;

      function IsNaN(value) {
        return typeof value === "number" && isNaN(value);
      }
      if (IsNaN(cha)) {
        return "";
      }
      let round2 = (cha / 1000 / 60 / 60 / 24).toFixed(2);
      let processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1);
      if (processingTime < 0) {
        return "0.0";
      } else if (processingTime < 0.1) {
        return "0.1";
      } else {
        return processingTime;
      }
    },
    // 待接单列表提交时间
    findData(val) {
      let statusArr = val.statuss;
      let statusTime = "";
      for (const i in statusArr) {
        if (statusArr[i].id == 1) {
          statusTime = statusArr[i].pivot.created_at;
        }
      }
      return statusTime;
    },
    // 处理时长
    getProcessingTime(value) {
      //获取接单的时间戳

      // createDay = createDay.replace(/-/g, "/");
      let createTime = new Date(value).getTime();
      //获取当前的时间戳
      var nowTime = new Date().getTime();
      //获取处理时间戳
      let cha = nowTime - createTime;

      function IsNaN(value) {
        return typeof value === "number" && isNaN(value);
      }
      if (IsNaN(cha)) {
        return "";
      }
      //转换天数
      let round2 = (cha / 1000 / 60 / 60 / 24).toFixed(2);
      let processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1);
      if (processingTime < 0) {
        return "0.0";
      } else if (processingTime < 0.1) {
        return "0.1";
      } else {
        return processingTime;
      }
    },
    // 处理耗时
    getWaitSubmitTime(value) {
      //获取接单的时间戳
      let createTime = new Date(value.created_at).getTime();
      let nowTime = "";
      if (value.status == "等待提交国知局") {
        nowTime = new Date().getTime();
      } else {
        nowTime = new Date(value.submit_at).getTime();
      }

      //获取处理时间戳
      let cha = nowTime - createTime;

      if (cha < 0) {
        cha = 0;
      }
      //转换天数
      let round2 = (cha / 1000 / 60 / 60 / 24).toFixed(2);
      let processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1);
      if (processingTime < 0) {
        return "0.0";
      } else if (processingTime < 0.1) {
        return "0.1";
      } else {
        return processingTime;
      }
    },
    agentNumAddName(value) {
      if (value) {
        if (value.email_work) {
          return `${value.name}（${value.email_work.split("@")[0].slice(-3)}）`;
        } else {
          return value.name;
        }
      } else {
        return "";
      }
    },
    // 答复耗时
    getTimeConsuming(value) {
      let createTime = "";
      if (value.statuss) {
        let sta = value.statuss;
        if (sta[sta.findIndex((v) => v.id == 20)]) {
          createTime = sta[sta.findIndex((v) => v.id == 20)].pivot.created_at;
        } else {
          createTime = value.updated_at;
        }
      } else {
        createTime = value.updated_at;
      }

      createTime = createTime.replace(/-/g, "/");
      createTime = new Date(createTime);
      //获取当前的时间戳
      var nowTime = "";
      if (value.status === "已补正" || value.status === "已答复") {
        let sta = value.statuss;
        let timeDate = "";
        if (sta[sta.findIndex((v) => v.id == 21)]) {
          timeDate = sta[sta.findIndex((v) => v.id == 21)].pivot.created_at;
        } else {
          return "";
        }
        nowTime = new Date(timeDate);
      } else {
        nowTime = new Date();
      }

      // let processingTime = ''
      //获取处理时间戳
      if (nowTime - createTime < 0) {
        return "";
      }
      let cha = nowTime - createTime;

      // var month = day * 30
      // let year = month * 12

      let round2 = (cha / 1000 / 60 / 60 / 24).toFixed(2);
      let processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1);
      if (processingTime < 0) {
        return "0.0";
      } else if (processingTime < 0.1) {
        return "0.1";
      } else {
        return processingTime;
      }
    },
    //接单时间
    getOrderTakingTime(val) {
      let statusArr = val.statuss;
      let createDay = "";
      for (const i in statusArr) {
        if (statusArr[i].id == 2) {
          createDay = statusArr[i].pivot.created_at;
        }
      }
      return createDay;
    },
    channelPid(value) {
      if (value) {
        if (value.referral_code) {
          return value.referral_code;
        } else {
          return "";
        }
      } else {
        return "";
      }
    },
    payStatus(value) {
      switch (value) {
        case 0:
          return "已缴费";
        case 1:
          return "已缴费";
        case 2:
          return "未缴费";
        case 3:
          return "已退款";
      }
    },
    // 结算详情导出 处理说明数据
    getExplainData(data, type) {
      let ExplainData = [];
      if (data && data.length > 0) {
        for (let i = 0; i < data.length; i++) {
          let item = `原因：${data[i].reason}，金额：${data[i].money}`;
          ExplainData.push(item);
        }
        ExplainData.join(",");
        return ExplainData;
      } else {
        return "";
      }
    },
    typeFilter(value) {
      if (value == "S") {
        return "实用新型";
      } else if (value == "F") {
        return "发明专利";
      } else if (value == "W") {
        return "外观设计";
      }
    },
    getAverage(value) {
      return (value.total_score / 3).toFixed(1);
    },
    withdrawStatus(value) {
      switch (value) {
        case 0:
          return "审核中";
        case 1:
          return "打款中";
        case 2:
          return "已打款";
        case 3:
          return "驳回";
      }
    },
    payType(value) {
      switch (value) {
        case 2:
          return "微信";
        case 3:
          return "支付宝";
        case 4:
          return "余额支付";
      }
    },
    // 答复列表发文日期
    getPost(value) {
      if (value.statuss) {
        let sta = value.statuss;
        if (sta[sta.findIndex((v) => v.id == 20)]) {
          return sta[sta.findIndex((v) => v.id == 20)].pivot.created_at;
        } else {
          return value.updated_at;
        }
      } else {
        return value.updated_at;
      }
    },
    getAnswerUpdateTime(value) {
      if (value.statuss) {
        let sta = value.statuss;
        if (sta[sta.findIndex((v) => v.id == 21)]) {
          return sta[sta.findIndex((v) => v.id == 21)].pivot.created_at;
        } else {
          return value.updated_at;
        }
      } else {
        return value.updated_at;
      }
    },
  },
  // 国知局前

  watch: {
    downLoadList: {
      handler: function (val) {
        this.myDownLoadList = val;
      },
    },
    myDownLoadList: {
      handler: function (val) {
        let flag = val.every((item) => item.isSelect);
        if (flag) {
          this.allSelect = true;
        } else {
          this.allSelect = false;
        }
      },
      deep: true,
    },
  },
};
</script>

<style lang='less' scoped>
.excelExport {
  .excelExport_btns {
    // line-height: 40px;
    .el-button {
      border: 1px solid #249dff;
      border-radius: 12px;
      padding: 5px 16px;
      display: inline-block;
      font-size: 15px;
      line-height: 1;
      color: #249dff;
      margin: 0 40px 10px 0;
    }

    .el-button:hover {
      background: rgba(36, 157, 255, 1);
      color: #fff;
    }
  }
}
</style>